package com.htgd.gardenexpo.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Component
public class WebConfigurationNew implements WebMvcConfigurer {


    @Value("${upload.absolute.weather}")
    public String weather_url;

    @Value("${upload.absolute.head}")
    public String head_url;

    @Value("${upload.absolute.my}")
    public String my_url;

    @Value("${upload.absolute.images}")
    public String images_url;
    @Value("${upload.absolute.icon}")
    public String icon_url;

    @Value("${upload.absolute.url}")
    public String absolute_url;

    @Value("${upload.absolute.plant}")
    public String plant_url;


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/h5/**").addResourceLocations(
                "classpath:/h5/");
        registry.addResourceHandler("/upload/**").addResourceLocations(
                "file:"+absolute_url).setCachePeriod(0);
        registry.addResourceHandler("/weather/**").addResourceLocations(
                "file:"+weather_url).setCachePeriod(0);
        registry.addResourceHandler("/head/**").addResourceLocations(
                "file:"+head_url).setCachePeriod(0);
        registry.addResourceHandler("/my/**").addResourceLocations(
                "file:"+my_url).setCachePeriod(0);
        registry.addResourceHandler("/icon/**").addResourceLocations(
                "file:"+icon_url).setCachePeriod(0);
        registry.addResourceHandler("/images/**").addResourceLocations(
                "file:"+images_url).setCachePeriod(0);
        registry.addResourceHandler("/plant/**").addResourceLocations(
                "file:"+plant_url).setCachePeriod(0);
        registry.addResourceHandler("swagger-ui.html").addResourceLocations(
                "classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations(
                "classpath:/META-INF/resources/webjars/");
        registry.addResourceHandler("/doc.html").addResourceLocations(
                "classpath:/META-INF/resources/");


    }
}
